import { View } from "../../../mvc/core/View";
import { ILayOut } from "../../../../modules/interfaces/ILayOut";
import { IClean } from "../../../../com/gengine/core/IClean";
import { LayerManager } from "../../manager/LayerManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { SceneRange } from "../../scene/map/SceneRange";
import { ObjCreate } from "./ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
//class CopyLeaveBtnView
    
    export  class CopyLeaveBtnView extends View implements ILayOut, IClean
    {
        constructor(arg1: Function=null)
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.resetPosition();
            this._callBack = arg1;
            this.addLeaveBtn();
            Dispatcher.addEventListener(EventName.StageResize, this.onStageResize);
            return;
        }

        /* internal  */onStageResize(arg1: DataEvent): void
        {
            this.resetPosition();
            return;
        }

        public resetPosition(): void
        {
            this.x = SceneRange.display.width - 300;
            this.y = 10;
            return;
        }

        public set call(arg1: Function)
        {
            this._callBack = arg1;
            return;
        }

        /* internal  */addLeaveBtn(): void
        {
            if (!this._leaveBtn) 
            {
                this._leaveBtn = ObjCreate.createGLoadedButton(ResFileConst.MagicTowerLeaveBtn, 0, 0, 50, 50, this);
                this._leaveBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onLeaveBtnClick);
            }
            return;
        }

        /* internal  */onLeaveBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._callBack != null) 
            {
                this._callBack.call();
            }
            return;
        }

        public clean(): void
        {
            Dispatcher.removeEventListener(EventName.StageResize, this.onStageResize);
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            return;
        }

        /* internal */ /* var */_callBack: Function;

        /* internal */ /* var */_leaveBtn: GLoadedButton;
    }
